(load "tiw-common")
(defun php-insert-head ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (insert "<?php
$IP = dirname( __FILE__ );

$path = array( $IP, \"$IP/lib\" );

set_include_path( implode( PATH_SEPARATOR, $path ) . PATH_SEPARATOR . get_include_path() );

?>")))
(defun php-outline-mode ()
  "set customized outline minor mode for Perl"
  (interactive)
  (setq outline-regexp
		"#!.\\|class\\|function\\|\\(=he\\)ad\\|\\(=po\\)d")
  (outline-minor-mode))
;; (add-hook 'php-mode-hook
;; 		  '(lambda () (and (setq outline-regexp "function") (outline-minor-mode))))

(defun my-php-mode-hook ()
;;  (setq tab-width 4
;;		c-basic-offset 4
;;		c-hanging-comment-ender-p nil
;;		c-set-style "bsd"
		(c-set-style "cc-mode")
		(abbrev-mode t)
		indent-tabs-mode
)
;;		(not
;;		 (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name))
;;			  (string-match "\.php$" (buffer-file-name))))))

(add-hook 'php-mode-hook 'my-php-mode-hook)


(load-file "~/lisppackage/snippet.el")

(defun my-snippet-php ()
  (define-abbrev-table 'php-mode-abbrev-table '())
  (snippet-with-abbrev-table
   'php-mode-abbrev-table
   ("ife"      .  "if ($$(test)) {$>\n$>$;\n}$>")
   ;; for mediawiki
   ("islogin"  . "\$wgUser->mId != 0")
   ("ingroup"  . "'in_array($$(sysop)', \$wgUser->getGroups())")
;;    ("for"     .  "for $$($${sequence}) {\n$;\n}")
    ("foreach" . "foreach ($$(array) as $$(element)) {$>\n$>$;\n}$>")
    ("wh"      .  "while ($$(test)) {$>\n$;\n}$>")
    ("whilex"   .  "while ($$(test)) {$>\n$;\n}$>")
	("ado"     .  "global \$wgDBuser, \$wgDBpassword, \$wgDBname, \$wgDBserver;\n  $$(object)= new $$(class)_adodb(\$wgDBuser, \$wgDBpassword, \$wgDBname, \$wgDBserver);\n$;$>")
	("wout"    .  "\$wgOut->addHTML(\"$$(html)\");$;")
	("docc"    .  "/**$>
 * $$(undocumented class)$>
 *$>
 * @package $$(default)$>
 * @author ting wang$>
 **/$>
class $$(classname)$>
{$>
$;$>
}$> // END class")
	("tryx"     .  "try {$>
	$;$>
} catch (Exception $$(e)) {$>
	$>
}$>
")
	("ifl"     .  "$$(retVal) = ($$(condition)) ? $$(a) : $$(b) ;$;")
	("ifx"      .  "if ($$(condition)) {$>
	$; $>
} $>")
	("rett"    .  "return true;")
	("retf"    .  "return false;")
	("docf"    .  "/**$>
 * $$(description)$>
 * $>
 * @return $$(return) $>
 **/$>
$>$$(public) function $$(name) ($$(param)) 
$>{
$;$>
}$>")
	("switchx"  .  "switch ($$) {
	case '$$': $>
		$$ $>
		break; $>
	$; $>
	default: $>
		$$ $>
		break;$>
}$>")
	("else"   .  "else {
$; $>
} $>")
	("echo"   .  "echo \"$$\";$;")
	;;    ("do"      .  "do {\n$;\n} while($$);")
))

(add-hook 'php-mode-hook 'adapt-snippet)

(add-hook 'php-mode-hook 'my-snippet-php)

(font-lock-add-keywords 'php-mode
						'(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)))



						